<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="反馈类型" prop="feedbackType">
        <el-select v-model="queryParams.feedbackType" placeholder="请选择反馈类型)" clearable>
          <el-option v-for="dict in dict.type.cms_feedback_type" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="反馈标题" prop="feedbackTitle">
        <el-input v-model="queryParams.feedbackTitle" placeholder="请输入反馈标题" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="处理等级" prop="handleLevel">
        <el-select v-model="queryParams.handleLevel" placeholder="请选择处理等级" clearable>
          <el-option v-for="dict in dict.type.cms_feedback_handle_level" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="反馈状态" prop="feedbackStatus">
        <el-select v-model="queryParams.feedbackStatus" placeholder="请选择反馈状态" clearable>
          <el-option v-for="dict in dict.type.cms_feedback_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="cmsFeedbackList" @selection-change="handleSelectionChange">
      <el-table-column label="编号" align="center" prop="id" width="60" />
      <el-table-column label="反馈类型" align="center" prop="feedbackType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cms_feedback_type" :value="scope.row.feedbackType" />
        </template>
      </el-table-column>
      <el-table-column label="反馈标题" align="center" prop="feedbackTitle" />
      <el-table-column label="反馈内容" align="center" prop="feedbackContent" />
      <el-table-column label="联系人" align="center" prop="contactName" />
      <el-table-column label="处理等级" align="center" prop="handleLevel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cms_feedback_handle_level" :value="scope.row.handleLevel" />
        </template>
      </el-table-column>
      <el-table-column label="反馈状态" align="center" prop="feedbackStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cms_feedback_status" :value="scope.row.feedbackStatus" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['cms:cmsFeedback:edit']" v-if="scope.row.feedbackStatus != 2">回复</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['cms:cmsFeedback:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改用户反馈对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="反馈类型" prop="feedbackType">
              <el-select v-model="form.feedbackType" placeholder="请选择反馈类型" disabled>
                <el-option v-for="dict in dict.type.cms_feedback_type" :key="dict.value" :label="dict.label"
                  :value="parseInt(dict.value)"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="反馈标题" prop="feedbackTitle">
              <el-input v-model="form.feedbackTitle" placeholder="请输入反馈标题" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="反馈内容" prop="feedbackContent">
              <el-input v-model="form.feedbackContent" type="textarea" placeholder="请输入内容" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人" prop="contactName">
              <el-input v-model="form.contactName" placeholder="请输入联系人" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="contactPhone">
              <el-input v-model="form.contactPhone" placeholder="请输入联系电话" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="反馈附件">
              <image-upload v-model="form.feedbackAttach" :isShowTip="false" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="回复内容" prop="replyContent">
          <el-input v-model="form.replyContent" type="textarea" placeholder="请输入内容" />
        </el-form-item>

        <el-form-item label="反馈状态">
          <el-radio-group v-model="form.feedbackStatus">
            <el-radio v-for="dict in dict.type.cms_feedback_status" :key="dict.value" :label="parseInt(dict.value)">
              {{ dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCmsFeedback, getCmsFeedback, delCmsFeedback, addCmsFeedback, updateCmsFeedback, replyCmsFeedback } from "@/api/cms/cmsFeedback";

export default {
  name: "CmsFeedback",
  dicts: ['cms_feedback_type', 'common_data_status', 'cms_feedback_handle_level', 'cms_feedback_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户反馈表格数据
      cmsFeedbackList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        uid: null,
        userId: null,
        deptId: null,
        contactName: null,
        contactPhone: null,
        feedbackType: null,
        feedbackTitle: null,
        feedbackContent: null,
        feedbackAttach: null,
        handleLevel: null,
        replyContent: null,
        replyBy: null,
        replyTime: null,
        feedbackStatus: null,
        comComment: null,
        comGrade: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户反馈列表 */
    getList() {
      this.loading = true;
      listCmsFeedback(this.queryParams).then(response => {
        this.cmsFeedbackList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        uid: null,
        userId: null,
        deptId: null,
        contactName: null,
        contactPhone: null,
        feedbackType: null,
        feedbackTitle: null,
        feedbackContent: null,
        feedbackAttach: null,
        handleLevel: null,
        replyContent: null,
        replyBy: null,
        replyTime: null,
        feedbackStatus: 0,
        comComment: null,
        comGrade: null,
        delFlag: null,
        status: 0,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户反馈";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCmsFeedback(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "回复用户反馈";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            replyCmsFeedback(this.form).then(response => {
              this.$modal.msgSuccess("回复成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCmsFeedback(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除用户反馈编号为"' + ids + '"的数据项？').then(function () {
        return delCmsFeedback(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('cms/cmsFeedback/export', {
        ...this.queryParams
      }, `cmsFeedback_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
